package com.sgb.knowledgeshare.view.fragment;


import com.swgk.core.base.AppFragment;

import java.util.HashMap;
import java.util.Map;
/*
*   分享的fragment管理类
 */
public class FragmentShareFactory {
    /**
     * 首页
     */
    public static final int SHARE_HOME = 0;
    /**
     * 分类
     */
    public static final int SHARE_CLASSIFY = 1;
    /**
     * 发布
     */
    public static final int SHARE_PUBLISH = 2;
    /**
     *消息
     */
    public static final int SHARE_MESSAGE = 3;
    /**
     * 我的
     */
    public static final int SHARE_MINE = 4;


    private static Map<Integer, AppFragment> mFragmentMap = new HashMap<>();

    public static AppFragment creatFragment(int index){
        AppFragment fragment = mFragmentMap.get(index);
        //如果之前没有创建，就创建新的
        if (fragment == null){
            switch (index){
                case SHARE_HOME:
                    fragment = new ShareMianFragment();
                    break;
                case SHARE_CLASSIFY:
                    fragment = new ShareClassifyFragment();
                    break;
                case SHARE_PUBLISH:
                  //  fragment = new SharePublishFragment();
                    break;
                case SHARE_MESSAGE:
                    fragment = new ShareMessageFragment();
                    break;
                case SHARE_MINE:
                    fragment = new ShareMineFragment();
                    break;
            }
            //把创建的fragment存起来
            mFragmentMap.put(index,fragment);
        }
        return fragment;
    }
}
